package com.sx.art2.controller;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.sx.art2.beans.Category;
import com.sx.art2.beans.Supplier;
import com.sx.art2.service.CategoryService;
import com.sx.art2.service.SupplierService;
    @Controller
public class SupplierController {
	@Autowired
	SupplierService supplierService;
	@Autowired
	CategoryService categoryService;
	@RequestMapping("/selectByjrTimesupplier")
	public ModelAndView list2(String time) {
		ModelAndView mv=new ModelAndView();
		List<Supplier> list2=supplierService.list2(time);
		mv.addObject("list2",list2);
		mv.setViewName("admin/supplierlist2");
		return mv;
	}
	@RequestMapping("/supplier")
	public ModelAndView list3() {
		ModelAndView mv=new ModelAndView();
		List<Supplier> list3=supplierService.list();
	    List<Category> categorylist=categoryService.list();	
		mv.addObject("list3",list3);
		mv.addObject("categorylist",categorylist);
		mv.setViewName("admin/addstock");

		return mv;
	}
	
	@RequestMapping("/listsupplier")
	public ModelAndView list() {
		ModelAndView mv=new ModelAndView();
		List<Supplier> list=supplierService.list();
		mv.addObject("list",list);
		mv.setViewName("admin/supplierlist1");
		return mv;
	}
	@RequestMapping("/addsupplier")
	@ResponseBody
	public String add(Supplier supplier) {
		String date="success";

		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
		supplier.setJrTime(df.format(new Date()));
		supplierService.add(supplier);
		return date;	
	}
	@RequestMapping("/updatesupplier")
	@ResponseBody
	public String update(Supplier supplier) {
		String date="success";
		supplierService.update(supplier);
		return date;
	}
	@RequestMapping("/deletesupplier")
	@ResponseBody
	public String delete(int supplierId) {
		String date="success";
		supplierService.delete(supplierId);
		return date;
	}
	@RequestMapping("/selectByIdsupplier")
	public ModelAndView selectById(int id) {
		ModelAndView mv=new ModelAndView();
		Supplier supplier=supplierService.selectById(id);
		mv.addObject("supplier",supplier);
		mv.setViewName("supplierupdate");
		return mv;
	}
	

}
